package cn.iocoder.yudao.module.shop.dal.mysql.order;

import java.time.LocalDateTime;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.shop.dal.dataobject.order.ShopOrderDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.shop.controller.admin.order.vo.*;

/**
 * 店内消耗订单 Mapper
 *
 * @author 曹建伟
 */
@Mapper
public interface ShopOrderMapper extends BaseMapperX<ShopOrderDO> {

    default PageResult<ShopOrderDO> selectPage(ShopOrderPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ShopOrderDO>()
                .eqIfPresent(ShopOrderDO::getNo, reqVO.getNo())
                .eqIfPresent(ShopOrderDO::getMemberId, reqVO.getMemberId())
                .eqIfPresent(ShopOrderDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ShopOrderDO::getTenantId, reqVO.getTenantId())
                .betweenIfPresent(ShopOrderDO::getStartTime, reqVO.getStartTime())
                .eqIfPresent(ShopOrderDO::getWalletCharge, reqVO.getWalletCharge())
                .eqIfPresent(ShopOrderDO::getPayStatus, reqVO.getPayStatus())
                .eq(ShopOrderDO::getDeleted, false)
                .betweenIfPresent(ShopOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopOrderDO::getId));
    }

    default List<ShopOrderDO> selectList(ShopOrderExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ShopOrderDO>()
                .eqIfPresent(ShopOrderDO::getNo, reqVO.getNo())
                .eqIfPresent(ShopOrderDO::getMemberId, reqVO.getMemberId())
                .eqIfPresent(ShopOrderDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(ShopOrderDO::getStartTime, reqVO.getStartTime())
                .eqIfPresent(ShopOrderDO::getWalletCharge, reqVO.getWalletCharge())
                .eqIfPresent(ShopOrderDO::getPayStatus, reqVO.getPayStatus())
                .betweenIfPresent(ShopOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShopOrderDO::getId));
    }

    default List<ShopOrderDO> selectNoCheckOrderList(LocalDateTime beforeTime, Long tenantId){
        return selectList(new LambdaQueryWrapperX<ShopOrderDO>()
                .le(ShopOrderDO::getStartTime, beforeTime)
                .eq(ShopOrderDO::getTenantId, tenantId)
                .eq(ShopOrderDO::getPayStatus, false)
                .eq(ShopOrderDO::getDeleted, false)
                .orderByDesc(ShopOrderDO::getStartTime));
    }

}
